package com.yutian.web.service.impl;

import com.github.pagehelper.Page;
import com.yutian.selfservice.support.UrlService;
import com.yutian.selfservice.support.mapper.UrlServiceMapper;
import com.yutian.selfservice.support.utils.PageSupport;
import com.yutian.selfservice.support.utils.Result;
import com.yutian.selfservice.support.utils.SnowflakeUtils;
import com.yutian.web.service.URLServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class URLServiceServiceImpl implements URLServiceService {
    @Autowired
    private UrlServiceMapper urlServiceMapper;
    @Override
    public Result list(UrlService urlService) {
        PageSupport.startPage();
        Page<UrlService> list = (Page<UrlService>) urlServiceMapper.selectList(urlService);
        return Result.successPage(list);
    }

    @Override
    public Result delete(Long id) {
        return urlServiceMapper.deleteByPrimaryKey(id)>0?Result.success():Result.fail("删除失败");
    }

    @Override
    public Result add(UrlService urlService) {
        urlService.setId(SnowflakeUtils.nextId());
        return urlServiceMapper.insert(urlService)>0?Result.success():Result.fail("删除失败");
    }

    @Override
    public UrlService selectById(Long id) {
        return urlServiceMapper.selectByKey(id);
    }

    @Override
    public Result edit(UrlService urlService) {
        return urlServiceMapper.updateByPrimaryKey(urlService)>0?Result.success():Result.fail("更新失败");
    }
}
